www.gusucode.com > Matlab动力系统和时间序列分析工具箱 > Matlab动力系统和时间序列分析工具箱/lab432/toolbox/global reconstruction/create_gr_model.m
function varargout = create_gr_model(varargin) % CREATE_GR_MODEL create model for global reconstruction % Batch mode using: GrModel=create_gr_model(X,model); % model - model function % X- data % example: GrModel=create_gr_model(X,'x1=c3*x3+c22*x2^2'); % % Last Modified by GUIDE v2.5 24-Jan-2004 12:17:31 % last modified 12.12.05 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @create_gr_model_OpeningFcn, ... 'gui_OutputFcn', @create_gr_model_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before create_gr_model is made visible. function create_gr_model_OpeningFcn(hObject, eventdata, handles, varargin) % hObject handle to figure % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to create_gr_model (see VARARGIN) % Choose default command line output for create_gr_model handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes create_gr_model wait for user response (see UIRESUME) % uiwait(handles.create_gr_model); global cgrmGLOBALS guidata(hObject, handles); if isempty(varargin) error('Not enougth input parameters'); else if isa(varargin{1},'struct') cgrmGLOBALS.x=varargin{1}; else cgrmGLOBALS.x.data=varargin{1}; [x,y]=size(varargin{1}); for i=1:y cgrmGLOBALS.x.name{i}=['crd_' num2str(i)]; end cgrmGLOBALS.x.time=(1:x)'; end end if length(varargin)==2 cgrmGLOBALS.auto=1; else cgrmGLOBALS.auto=0; end if length(varargin)<2 cgrmGLOBALS.model=''; show_lin_model(handles); else cgrmGLOBALS.model=varargin{2}; set(handles.edit_gm,'string',cgrmGLOBALS.model); end STR=[]; STR_listbox=[]; for i=1:length(cgrmGLOBALS.x.name) STR=[STR '|' cgrmGLOBALS.x.name{i}]; STR_listbox{i}=['''x' num2str(i) ''' is ' cgrmGLOBALS.x.name{i}]; end set(handles.popup_menu,'string',STR(2:end)); set(handles.listbox,'string',STR_listbox) guidata(hObject, handles); % --- Outputs from this function are returned to the command line. function varargout = create_gr_model_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure global cgrmGLOBALS if cgrmGLOBALS.auto compute_button_Callback(handles.compute_button, [], handles); if nargout varargout{1} =cgrmGLOBALS.modelinfo; end else uiwait; try if nargout varargout{1} =cgrmGLOBALS.modelinfo; end catch end end try close(handles.create_gr_model); catch end % --- Executes on button press in lin_model_button. function lin_model_button_Callback(hObject, eventdata, handles) % hObject handle to lin_model_button (see GCBO) % handles structure with handles and user data (see GUIDATA) set(hObject,'value',1); set([handles.quadric_model_button handles.cubic_model_button],'value',0); show_lin_model(handles); % --- Executes on button press in quadric_model_button. function quadric_model_button_Callback(hObject, eventdata, handles) % hObject handle to quadric_model_button (see GCBO) % handles structure with handles and user data (see GUIDATA) set(hObject,'value',1); set([handles.lin_model_button handles.cubic_model_button],'value',0); show_quadric_model(handles); % --- Executes on button press in cubic_model_button. function cubic_model_button_Callback(hObject, eventdata, handles) % hObject handle to cubic_model_button (see GCBO) % handles structure with handles and user data (see GUIDATA) set(hObject,'value',1); set([handles.quadric_model_button handles.lin_model_button],'value',0); show_cubic_model(handles); % --- Executes during object creation, after setting all properties. function edit_gm_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_gm (see GCBO) % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end function edit_gm_Callback(hObject, eventdata, handles) % hObject handle to edit_gm (see GCBO) % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit_gm as text % str2double(get(hObject,'String')) returns contents of edit_gm as a double % --- Executes on button press in close_button. function close_button_Callback(hObject, eventdata, handles) % hObject handle to close_button (see GCBO) % handles structure with handles and user data (see GUIDATA) close(handles.create_gr_model); % --- Executes on button press in compute_button. function compute_button_Callback(hObject, eventdata, handles) % hObject handle to compute_button (see GCBO) % handles structure with handles and user data (see GUIDATA) global cgrmGLOBALS gm=get(handles.edit_gm,'string'); for i=1:length(gm) if gm(i)=='=' break end end [coeff_names,funcs]=da_df_parser(gm(i+1:end)); modelinfo.coeffs=coeff_names; modelinfo.funcs=funcs; modelinfo.left_part=gm(1:i-1); modelinfo.gm=gm; modelinfo.x=cgrmGLOBALS.x; gm=gr_algorithm(modelinfo); cgrmGLOBALS.modelinfo=gm; uiresume; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function str=show_lin_model(handles); global cgrmGLOBALS crdNo=length(cgrmGLOBALS.x.name); unique_crd_num=get(handles.popup_menu,'value'); str=sprintf('x%d=',unique_crd_num); for i=1:crdNo if str(end)=='=' if unique_crd_num~=i str=[str sprintf('c%d*x%d',i,i)]; end else if unique_crd_num~=i str=[str '+' sprintf('c%d*x%d',i,i)]; end end end set(handles.edit_gm,'string',str); function str=show_quadric_model(handles); global cgrmGLOBALS crdNo=length(cgrmGLOBALS.x.name); str=show_lin_model(handles); unique_crd_num=get(handles.popup_menu,'value'); for i=1:crdNo if unique_crd_num~=i str=[str '+' sprintf('c%d%d*x%d^2',i,i,i)]; end end for i=1:crdNo for j=i+1:crdNo if (unique_crd_num~=i)&(unique_crd_num~=j) str=[str '+' sprintf('c%d%d*x%d*x%d',i,j,i,j)]; end end end set(handles.edit_gm,'string',str); function show_cubic_model(handles); global cgrmGLOBALS crdNo=length(cgrmGLOBALS.x.name); str=show_quadric_model(handles); unique_crd_num=get(handles.popup_menu,'value'); for i=1:crdNo if unique_crd_num~=i str=[str '+' sprintf('c%d%d%d*x%d^3',i,i,i,i)]; end end for i=1:crdNo for j=1:crdNo if i~=j if (unique_crd_num~=i)&(unique_crd_num~=j) str=[str '+' sprintf('c%d%d%d*x%d^2*x%d',i,i,j,i,j)]; end end end end for i=1:crdNo for j=i+1:crdNo for k=j+1:crdNo if (unique_crd_num~=i)&(unique_crd_num~=j)&(unique_crd_num~=k) str=[str '+' sprintf('c%d%d%d*x%d*x%d*x%d',i,j,k,i,j,k)]; end end end end set(handles.edit_gm,'string',str); % --- Executes during object creation, after setting all properties. function popup_menu_CreateFcn(hObject, eventdata, handles) % hObject handle to popup_menu (see GCBO) % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes on selection change in popup_menu. function popup_menu_Callback(hObject, eventdata, handles) % hObject handle to popup_menu (see GCBO) % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns popup_menu contents as cell array % contents{get(hObject,'Value')} returns selected item from popup_menu if get(handles.cubic_model_button,'value') show_cubic_model(handles); end if get(handles.quadric_model_button,'value') show_quadric_model(handles); end if get(handles.lin_model_button,'value') show_lin_model(handles); end % --- Executes during object creation, after setting all properties. function listbox_CreateFcn(hObject, eventdata, handles) % hObject handle to listbox (see GCBO) % handles empty - handles not created until after all CreateFcns called % Hint: listbox controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes on selection change in listbox. function listbox_Callback(hObject, eventdata, handles) % hObject handle to listbox (see GCBO) % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns listbox contents as cell array % contents{get(hObject,'Value')} returns selected item from listbox